﻿layui.use(['layer', 'form', 'util'], function () {
    var layer = layui.layer;
    var $ = layui.jquery;
    var form = layui.form;
    var util = layui.util;
    //钩子函数
    $(function () {
        generateDate();
    });

    //自动生成时间
    function generateDate() {
        var n = new Date();
        var ss = "LL" + n.getFullYear() + (n.getMonth() + 1).toString().padStart(2, '0') +
            n.getDate().toString().padStart(2, '0') +
            n.getHours().toString().padStart(2, '0') +
            n.getMinutes().toString().padStart(2, '0') +
            n.getSeconds().toString().padStart(2, '0');
        $("#pickingNo").val(ss);
    }

    //弹出层显示成品
    function addIngredient() {

    }

    //生产领料添加
    form.on('submit(formDemo)', function (data) {
        var dto = data.field; // 获取表单字段值
        console.log(data);
        $.ajax({
            url: '/Warehouse/AddPicking',
            type: 'post',
            data: {
                dto: dto,
                token: localStorage.getItem("token")
            },
            success: function (res) {
                var res = JSON.parse(res)
                console.log(dto);
                console.log(res);
                if (res.code == 0) {
                    layer.alert("添加成功");
                    setTimeout(function () {
                        location.href = '/Warehouse/PickingShow'
                    }, 2000);
                } else {
                    layer.alert("添加失败");
                }
            }
        });

        return false; // 阻止默认 form 跳转
    });
    // 对弹层中的表单进行初始化渲染
    form.render();
});